package cn.wolfcode.web.service.impl;

import cn.wolfcode.web.domain.Employee;
import cn.wolfcode.web.mapper.EmployeeMapper;
import cn.wolfcode.web.service.IUpdatePasswordService;
import cn.wolfcode.web.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class IUpdatePasswordServiceImpl implements IUpdatePasswordService {
    @Autowired
    private EmployeeMapper employeeMapper;
//    @Autowired
//    private HttpSession session;

    @Override
    public Employee selectPassword(String oldPassword) {
     Employee employee = (Employee) UserContext.getSession().getAttribute("employee");
        employee.getName();
        if (!employee.getPassword().equals(oldPassword)) {
            throw new RuntimeException("密码错误");
        }

//       Employee selectByPasswordEmployee = employeeMapper.selectUsernameAndPassword(employee.getName(), oldPassword);
//        if (selectByPasswordEmployee == null) {
//            throw new RuntimeException("密码错误");
//        }
//        return selectByPasswordEmployee;
        return employee;
    }

    @Override
    public Employee UpdatePassword(Employee employee) {

        return employeeMapper.updatePassword(employee);
    }
}
